package com.xiaocheng.core.integer;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

import javax.xml.transform.Templates;

/**
 * 
* @ClassName: IntegerExchange 
* @Description: 两个Integer的值交换
* @author 高亚鹏
* @date 2018年5月9日 上午11:23:10 
*
 */
public class IntegerExchange {
	public static void main(String[] args) {
		Integer a = 10;
		Integer b = 12;
		cwarp(a,b);
		System.out.println("a的值为：" + a + " b的值为：" + b);
		
	}

	private static void cwarp(Integer a,Integer b) {
		/*java 都是按值传递的,操作的都是地址副本，所以这个方法不行*/
//		Integer temp = a;
//		a = b;
//		b = temp;
		
		/**/
		Class<?> clazz = Integer.class;
		try {
			Field field = clazz.getDeclaredField("value");
			field.setAccessible(true);
			Integer temp = new Integer(a);
			System.out.println(temp);
			field.set(a, b);
			System.out.println(temp);
			field.set(b, temp);
			field.setAccessible(false);
		} catch (NoSuchFieldException e) {
			
			e.printStackTrace();
		} catch (SecurityException e) {
			
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			
			e.printStackTrace();
		}
		
		
	}
}
